# -*- encoding: utf-8 -*-
'''
@File    :   kaowuyou.py
@Time    :   2019/09/04 16:47:36
@Author  :   Axi 
@Version :   1.0
@Contact :   785934566@qq.com
@Desc    :   考无忧网校
'''

# here put the import lib

import pymongo
import re
import time
import random
from requests_html import HTMLSession


session = HTMLSession()
sleep_time = random.randint(3, 5)
# 连接数据库
client = pymongo.MongoClient('mongodb://114.67.96.255:27017')
database = client.kaowuyou
yijian_doc = database.kaowuyou_yijian
ua_list = [
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134',
    'Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
    'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0',
    'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/18.17763',
    'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
    'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
    'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko)',
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
    'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
    'Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; 125LA; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko)',
    'Mozilla/5.0 (X11; U; Linux Core i7-4980HQ; de; rv:32.0; compatible; JobboerseBot; http://www.jobboerse.com/bot.htm) Gecko/20100101 Firefox/38.0',
    'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)',
    'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
    'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
    'Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)',
]
ua = random.choice(ua_list)

headers = {
    'Host': 'www.k51.com.cn',
    'user-agent': ua,
}

topic_urllist = [
    "http://www.k51.com.cn/Questions/73/1",
    "http://www.k51.com.cn/Questions/73/2",
    "http://www.k51.com.cn/Questions/73/3",
    "http://www.k51.com.cn/Questions/73/4",
    "http://www.k51.com.cn/Questions/73/5",
    "http://www.k51.com.cn/Questions/73/6",
    "http://www.k51.com.cn/Questions/73/7",
    "http://www.k51.com.cn/Questions/73/8",
    "http://www.k51.com.cn/Questions/73/9",
    "http://www.k51.com.cn/Questions/73/10",
    "http://www.k51.com.cn/Questions/73/11",
    "http://www.k51.com.cn/Questions/73/12",
    "http://www.k51.com.cn/Questions/73/13",
    "http://www.k51.com.cn/Questions/73/14",
    "http://www.k51.com.cn/Questions/73/15",
    "http://www.k51.com.cn/Questions/73/16",
    "http://www.k51.com.cn/Questions/73/17",
    "http://www.k51.com.cn/Questions/73/18",
    "http://www.k51.com.cn/Questions/73/19",
    "http://www.k51.com.cn/Questions/73/20",
    "http://www.k51.com.cn/Questions/73/21",
    "http://www.k51.com.cn/Questions/73/22",
    "http://www.k51.com.cn/Questions/73/23",
    "http://www.k51.com.cn/Questions/73/24",
    "http://www.k51.com.cn/Questions/73/25",
    "http://www.k51.com.cn/Questions/73/26",
    "http://www.k51.com.cn/Questions/73/27",
    "http://www.k51.com.cn/Questions/73/28",
    "http://www.k51.com.cn/Questions/73/29",
    "http://www.k51.com.cn/Questions/73/30",
    "http://www.k51.com.cn/Questions/73/31",
    "http://www.k51.com.cn/Questions/73/32",
    "http://www.k51.com.cn/Questions/73/33",
    "http://www.k51.com.cn/Questions/73/34",
    "http://www.k51.com.cn/Questions/73/35",
    "http://www.k51.com.cn/Questions/73/36",
    "http://www.k51.com.cn/Questions/73/37",
    "http://www.k51.com.cn/Questions/73/38",
    "http://www.k51.com.cn/Questions/73/39",
    "http://www.k51.com.cn/Questions/73/40",
    "http://www.k51.com.cn/Questions/73/41",
    "http://www.k51.com.cn/Questions/73/42",
    "http://www.k51.com.cn/Questions/73/43",
    "http://www.k51.com.cn/Questions/73/44",
    "http://www.k51.com.cn/Questions/73/45",
    "http://www.k51.com.cn/Questions/73/46",
    "http://www.k51.com.cn/Questions/73/47",
    "http://www.k51.com.cn/Questions/73/48",
    "http://www.k51.com.cn/Questions/73/49",
    "http://www.k51.com.cn/Questions/73/50",
    "http://www.k51.com.cn/Questions/73/51",
    "http://www.k51.com.cn/Questions/73/52",
    "http://www.k51.com.cn/Questions/73/53",
    "http://www.k51.com.cn/Questions/73/54",
    "http://www.k51.com.cn/Questions/73/55",
    "http://www.k51.com.cn/Questions/73/56",
    "http://www.k51.com.cn/Questions/73/57",
    "http://www.k51.com.cn/Questions/73/58",
    "http://www.k51.com.cn/Questions/73/59",
    "http://www.k51.com.cn/Questions/73/60",
    "http://www.k51.com.cn/Questions/73/61",
    "http://www.k51.com.cn/Questions/73/62",
    "http://www.k51.com.cn/Questions/73/63",
    "http://www.k51.com.cn/Questions/73/64",
    "http://www.k51.com.cn/Questions/73/65",
    "http://www.k51.com.cn/Questions/73/66",
    "http://www.k51.com.cn/Questions/73/67",
    "http://www.k51.com.cn/Questions/73/68",
    "http://www.k51.com.cn/Questions/73/69",
    "http://www.k51.com.cn/Questions/73/70",
    "http://www.k51.com.cn/Questions/73/71",
    "http://www.k51.com.cn/Questions/73/72",
    "http://www.k51.com.cn/Questions/73/73",
    "http://www.k51.com.cn/Questions/73/74",
    "http://www.k51.com.cn/Questions/73/75",
    "http://www.k51.com.cn/Questions/73/76",
    "http://www.k51.com.cn/Questions/73/77",
    "http://www.k51.com.cn/Questions/73/78",
    "http://www.k51.com.cn/Questions/73/79",
    "http://www.k51.com.cn/Questions/73/80",
    "http://www.k51.com.cn/Questions/73/81",
    "http://www.k51.com.cn/Questions/73/82",
    "http://www.k51.com.cn/Questions/73/83",
    "http://www.k51.com.cn/Questions/73/84",
    "http://www.k51.com.cn/Questions/73/85",
    "http://www.k51.com.cn/Questions/73/86",
    "http://www.k51.com.cn/Questions/73/87",
    "http://www.k51.com.cn/Questions/73/88",
    "http://www.k51.com.cn/Questions/73/89",
    "http://www.k51.com.cn/Questions/73/90",
    "http://www.k51.com.cn/Questions/73/91",
    "http://www.k51.com.cn/Questions/73/92",
    "http://www.k51.com.cn/Questions/73/93",
    "http://www.k51.com.cn/Questions/73/94",
    "http://www.k51.com.cn/Questions/73/95",
    "http://www.k51.com.cn/Questions/73/96",
    "http://www.k51.com.cn/Questions/73/97",
    "http://www.k51.com.cn/Questions/73/98",
    "http://www.k51.com.cn/Questions/73/99",
    "http://www.k51.com.cn/Questions/73/100",
    "http://www.k51.com.cn/Questions/73/101",
    "http://www.k51.com.cn/Questions/73/102",
    "http://www.k51.com.cn/Questions/73/103",
    "http://www.k51.com.cn/Questions/73/104",
    "http://www.k51.com.cn/Questions/73/105",
    "http://www.k51.com.cn/Questions/73/106",
    "http://www.k51.com.cn/Questions/73/107",
    "http://www.k51.com.cn/Questions/73/108",
    "http://www.k51.com.cn/Questions/73/109",
    "http://www.k51.com.cn/Questions/73/110",
    "http://www.k51.com.cn/Questions/73/111",
    "http://www.k51.com.cn/Questions/73/112",
    "http://www.k51.com.cn/Questions/73/113",
    "http://www.k51.com.cn/Questions/73/114",
    "http://www.k51.com.cn/Questions/73/115",
    "http://www.k51.com.cn/Questions/73/116",
    "http://www.k51.com.cn/Questions/73/117",
    "http://www.k51.com.cn/Questions/73/118",
    "http://www.k51.com.cn/Questions/73/119",
    "http://www.k51.com.cn/Questions/73/120",
    "http://www.k51.com.cn/Questions/73/121",
    "http://www.k51.com.cn/Questions/73/122",
    "http://www.k51.com.cn/Questions/73/123",
    "http://www.k51.com.cn/Questions/73/124",
    "http://www.k51.com.cn/Questions/73/125",
    "http://www.k51.com.cn/Questions/73/126",
    "http://www.k51.com.cn/Questions/73/127",
    "http://www.k51.com.cn/Questions/73/128",
    "http://www.k51.com.cn/Questions/73/129",
    "http://www.k51.com.cn/Questions/73/130",
    "http://www.k51.com.cn/Questions/73/131",
    "http://www.k51.com.cn/Questions/73/132",
    "http://www.k51.com.cn/Questions/73/133",
    "http://www.k51.com.cn/Questions/73/134",
    "http://www.k51.com.cn/Questions/73/135",
    "http://www.k51.com.cn/Questions/73/136",
    "http://www.k51.com.cn/Questions/73/137",
    "http://www.k51.com.cn/Questions/73/138",
    "http://www.k51.com.cn/Questions/73/139",
    "http://www.k51.com.cn/Questions/73/140",
    "http://www.k51.com.cn/Questions/73/141",
    "http://www.k51.com.cn/Questions/73/142",
    "http://www.k51.com.cn/Questions/73/143",
    "http://www.k51.com.cn/Questions/73/144",
    "http://www.k51.com.cn/Questions/73/145",
    "http://www.k51.com.cn/Questions/73/146",
    "http://www.k51.com.cn/Questions/73/147",
    "http://www.k51.com.cn/Questions/73/148",
    "http://www.k51.com.cn/Questions/73/149",
    "http://www.k51.com.cn/Questions/73/150",
    "http://www.k51.com.cn/Questions/73/151",
    "http://www.k51.com.cn/Questions/73/152",
    "http://www.k51.com.cn/Questions/73/153",
    "http://www.k51.com.cn/Questions/73/154",
    "http://www.k51.com.cn/Questions/73/155",
    "http://www.k51.com.cn/Questions/73/156",
    "http://www.k51.com.cn/Questions/73/157",
    "http://www.k51.com.cn/Questions/73/158",
    "http://www.k51.com.cn/Questions/73/159",
    "http://www.k51.com.cn/Questions/73/160",
    "http://www.k51.com.cn/Questions/73/161",
    "http://www.k51.com.cn/Questions/73/162",
    "http://www.k51.com.cn/Questions/73/163",
    "http://www.k51.com.cn/Questions/73/164",
    "http://www.k51.com.cn/Questions/73/165",
    "http://www.k51.com.cn/Questions/73/166",
    "http://www.k51.com.cn/Questions/73/167",
    "http://www.k51.com.cn/Questions/73/168",
    "http://www.k51.com.cn/Questions/73/169",
    "http://www.k51.com.cn/Questions/73/170",
    "http://www.k51.com.cn/Questions/73/171",
    "http://www.k51.com.cn/Questions/73/172",
    "http://www.k51.com.cn/Questions/73/173",
    "http://www.k51.com.cn/Questions/73/174",
    "http://www.k51.com.cn/Questions/73/175",
    "http://www.k51.com.cn/Questions/73/176",
    "http://www.k51.com.cn/Questions/73/177",
    "http://www.k51.com.cn/Questions/73/178",
    "http://www.k51.com.cn/Questions/73/179",
    "http://www.k51.com.cn/Questions/73/180",
    "http://www.k51.com.cn/Questions/73/181",
    "http://www.k51.com.cn/Questions/73/182",
    "http://www.k51.com.cn/Questions/73/183",
    "http://www.k51.com.cn/Questions/73/184",
    "http://www.k51.com.cn/Questions/73/185",
    "http://www.k51.com.cn/Questions/73/186",
    "http://www.k51.com.cn/Questions/73/187",
    "http://www.k51.com.cn/Questions/73/188",
    "http://www.k51.com.cn/Questions/73/189",
    "http://www.k51.com.cn/Questions/73/190",
    "http://www.k51.com.cn/Questions/73/191",
    "http://www.k51.com.cn/Questions/73/192",
    "http://www.k51.com.cn/Questions/73/193",
    "http://www.k51.com.cn/Questions/73/194",
    "http://www.k51.com.cn/Questions/73/195",
    "http://www.k51.com.cn/Questions/73/196",
    "http://www.k51.com.cn/Questions/73/197",
    "http://www.k51.com.cn/Questions/73/198",
    "http://www.k51.com.cn/Questions/73/199",
    "http://www.k51.com.cn/Questions/73/200",
    "http://www.k51.com.cn/Questions/73/201",
    "http://www.k51.com.cn/Questions/73/202",
    "http://www.k51.com.cn/Questions/73/203",
    "http://www.k51.com.cn/Questions/73/204",
    "http://www.k51.com.cn/Questions/73/205",
    "http://www.k51.com.cn/Questions/73/206",
    "http://www.k51.com.cn/Questions/73/207",
    "http://www.k51.com.cn/Questions/73/208",
    "http://www.k51.com.cn/Questions/73/209",
    "http://www.k51.com.cn/Questions/73/210",
    "http://www.k51.com.cn/Questions/73/211",
    "http://www.k51.com.cn/Questions/73/212",
    "http://www.k51.com.cn/Questions/73/213",
    "http://www.k51.com.cn/Questions/73/214",
    "http://www.k51.com.cn/Questions/73/215",
    "http://www.k51.com.cn/Questions/73/216",
    "http://www.k51.com.cn/Questions/73/217",
    "http://www.k51.com.cn/Questions/73/218",
    "http://www.k51.com.cn/Questions/73/219",
    "http://www.k51.com.cn/Questions/73/220",
    "http://www.k51.com.cn/Questions/73/221",
    "http://www.k51.com.cn/Questions/73/222",
    "http://www.k51.com.cn/Questions/73/223",
    "http://www.k51.com.cn/Questions/73/224",
    "http://www.k51.com.cn/Questions/73/225",
    "http://www.k51.com.cn/Questions/73/226",
    "http://www.k51.com.cn/Questions/73/227",
    "http://www.k51.com.cn/Questions/73/228",
    "http://www.k51.com.cn/Questions/73/229",
    "http://www.k51.com.cn/Questions/73/230",
    "http://www.k51.com.cn/Questions/73/231",
    "http://www.k51.com.cn/Questions/73/232",
    "http://www.k51.com.cn/Questions/73/233",
    "http://www.k51.com.cn/Questions/73/234",
    "http://www.k51.com.cn/Questions/73/235",
    "http://www.k51.com.cn/Questions/73/236",
    "http://www.k51.com.cn/Questions/73/237",
    "http://www.k51.com.cn/Questions/73/238",
    "http://www.k51.com.cn/Questions/73/239",
    "http://www.k51.com.cn/Questions/73/240",
    "http://www.k51.com.cn/Questions/73/241",
    "http://www.k51.com.cn/Questions/73/242",
    "http://www.k51.com.cn/Questions/73/243",
    "http://www.k51.com.cn/Questions/73/244",
    "http://www.k51.com.cn/Questions/73/245",
    "http://www.k51.com.cn/Questions/73/246",
    "http://www.k51.com.cn/Questions/73/247",
    "http://www.k51.com.cn/Questions/73/248",
    "http://www.k51.com.cn/Questions/73/249",
    "http://www.k51.com.cn/Questions/73/250",
    "http://www.k51.com.cn/Questions/73/251",
    "http://www.k51.com.cn/Questions/73/252",
    "http://www.k51.com.cn/Questions/73/253",
    "http://www.k51.com.cn/Questions/73/254",
    "http://www.k51.com.cn/Questions/73/255",
    "http://www.k51.com.cn/Questions/73/256",
    "http://www.k51.com.cn/Questions/73/257",
    "http://www.k51.com.cn/Questions/73/258",
    "http://www.k51.com.cn/Questions/73/259",
    "http://www.k51.com.cn/Questions/73/260",
    "http://www.k51.com.cn/Questions/73/261",
    "http://www.k51.com.cn/Questions/73/262",
    "http://www.k51.com.cn/Questions/73/263",
    "http://www.k51.com.cn/Questions/73/264",
    "http://www.k51.com.cn/Questions/73/265",
    "http://www.k51.com.cn/Questions/73/266",
    "http://www.k51.com.cn/Questions/73/267",
    "http://www.k51.com.cn/Questions/73/268",
    "http://www.k51.com.cn/Questions/73/269",
    "http://www.k51.com.cn/Questions/73/270",
    "http://www.k51.com.cn/Questions/73/271",
    "http://www.k51.com.cn/Questions/73/272",
    "http://www.k51.com.cn/Questions/73/273",
    "http://www.k51.com.cn/Questions/73/274",
    "http://www.k51.com.cn/Questions/73/275",
    "http://www.k51.com.cn/Questions/73/276",
    "http://www.k51.com.cn/Questions/73/277",
    "http://www.k51.com.cn/Questions/73/278",
    "http://www.k51.com.cn/Questions/73/279",
    "http://www.k51.com.cn/Questions/73/280",
    "http://www.k51.com.cn/Questions/73/281",
    "http://www.k51.com.cn/Questions/73/282",
    "http://www.k51.com.cn/Questions/73/283",
    "http://www.k51.com.cn/Questions/73/284",
    "http://www.k51.com.cn/Questions/73/285",
    "http://www.k51.com.cn/Questions/73/286",
    "http://www.k51.com.cn/Questions/73/287",
    "http://www.k51.com.cn/Questions/73/288",
    "http://www.k51.com.cn/Questions/73/289",
    "http://www.k51.com.cn/Questions/73/290",
    "http://www.k51.com.cn/Questions/73/291",
    "http://www.k51.com.cn/Questions/73/292",
    "http://www.k51.com.cn/Questions/73/293",
    "http://www.k51.com.cn/Questions/73/294",
    "http://www.k51.com.cn/Questions/73/295",
    "http://www.k51.com.cn/Questions/73/296",
    "http://www.k51.com.cn/Questions/73/297",
    "http://www.k51.com.cn/Questions/73/298",
    "http://www.k51.com.cn/Questions/73/299",
    "http://www.k51.com.cn/Questions/73/300",
    "http://www.k51.com.cn/Questions/73/301",
    "http://www.k51.com.cn/Questions/73/302",
    "http://www.k51.com.cn/Questions/73/303",
    "http://www.k51.com.cn/Questions/73/304",
    "http://www.k51.com.cn/Questions/73/305",
    "http://www.k51.com.cn/Questions/73/306",
    "http://www.k51.com.cn/Questions/73/307",
    "http://www.k51.com.cn/Questions/73/308",
    "http://www.k51.com.cn/Questions/73/309",
    "http://www.k51.com.cn/Questions/73/310",
    "http://www.k51.com.cn/Questions/73/311",
    "http://www.k51.com.cn/Questions/73/312",
    "http://www.k51.com.cn/Questions/73/313",
    "http://www.k51.com.cn/Questions/73/314",
    "http://www.k51.com.cn/Questions/73/315",
    "http://www.k51.com.cn/Questions/73/316",
    "http://www.k51.com.cn/Questions/73/317",
    "http://www.k51.com.cn/Questions/73/318",
    "http://www.k51.com.cn/Questions/73/319",
    "http://www.k51.com.cn/Questions/73/320",
    "http://www.k51.com.cn/Questions/73/321",
    "http://www.k51.com.cn/Questions/73/322",
    "http://www.k51.com.cn/Questions/73/323",
    "http://www.k51.com.cn/Questions/73/324",
    "http://www.k51.com.cn/Questions/73/325",
    "http://www.k51.com.cn/Questions/73/326",
    "http://www.k51.com.cn/Questions/73/327",
    "http://www.k51.com.cn/Questions/73/328",
    "http://www.k51.com.cn/Questions/73/329",
    "http://www.k51.com.cn/Questions/73/330",
    "http://www.k51.com.cn/Questions/73/331",
    "http://www.k51.com.cn/Questions/73/332",
    "http://www.k51.com.cn/Questions/73/333",
    "http://www.k51.com.cn/Questions/73/334",
    "http://www.k51.com.cn/Questions/73/335",
    "http://www.k51.com.cn/Questions/73/336",
    "http://www.k51.com.cn/Questions/73/337",
    "http://www.k51.com.cn/Questions/73/338",
    "http://www.k51.com.cn/Questions/73/339",
    "http://www.k51.com.cn/Questions/73/340",
    "http://www.k51.com.cn/Questions/73/341",

]


def topic_url():
    for topic_url in topic_urllist:
        try:
            resp = session.get(topic_url, headers=headers, verify=False,)
            time.sleep(sleep_time)
        except Exception as e:
            print('列表页出现错误-------{}'.format(e))
        url_list = resp.html.xpath(
            "//div[contains(@class,'QuestionContent')]/a")
        for url in url_list:
            url_yield = ''.join(url.absolute_links)
            yield url_yield


def detial_content(url_yeild):
    num = 0

    for url in url_yeild:
        start_time = time.perf_counter()
        try:
            resp = session.get(url, headers=headers, timeout=3)
            time.sleep(sleep_time)
            item = {}
            # 标题
            item['title'] = ''.join(resp.html.xpath(
                "//div[contains(@class,'cont-details-cont-topic')]/strong/text()")).replace('\u3000', '')
            # 内容
            content_list = resp.html.xpath(
                "//div[contains(@class,'cont-details-cont-topic')]/ul/li//text()")
            con = []
            for content in content_list:
                content = '<p>' + item['title'] + '</p>' + '<p>' + content + '</p>'
                con.append(content.replace('\u3000', ''))
            item['content'] = ''.join(con)
            # url
            item['url'] = url
            print(item)
            num += 1
            print('=======正在抓取的是第 {} 个========='.format(num))
            yijian_doc.insert_one(item)
            print('{} ---插入数据库成功'.format(item['title']))
        except Exception as e:
            print('详情页抓取错误-------{}'.format(e))
            continue
        all_time = time.perf_counter() - start_time
        print('抓取用时{}'.format(all_time))


if __name__ == "__main__":
    url_yeild = topic_url()
    detial_content(url_yeild)
